<template>
  <div ref="container"
       class="wrapper">
    <div>
      <!-- hot-city-html -->
      <div class="hot-city">
        <div class="hot-title">
          <span>热门城市</span>
        </div>
        <div class="hot-list">
          <ul class="hot-ul">
            <li class="hot-li"
                v-for="item in hotCityList"
                :key="item.id"
                @click="changeLocalCity(item.cityName)">
              {{item.cityName}}
            </li>
          </ul>
        </div>
      </div>

      <!-- letter-html -->
      <div class="letter">
        <div class="letter-title">
          <span>字母排序</span>
        </div>
        <div class="letter-list">
          <ul class="letter-ul">
            <li class="letter-li"
                v-for="item in cityList"
                :key="item.id"
                @click="changeLetter(item.id)">
              {{item.title}}
            </li>
            <li class="letter-empty"></li>
            <li class="letter-empty"></li>
            <li class="letter-empty"></li>
            <li class="letter-empty"></li>
            <li class="letter-empty"></li>
            <li class="letter-empty"></li>
          </ul>
        </div>
      </div>

      <!-- allcity-list-html -->
      <div>
        <div class="abc"
             v-for="(item,index) in cityList"
             :key="index"
             ref="cityList">
          <div class="abc-title">
            <span>{{item.title}}</span>
          </div>
          <div class="abc-list">
            <ul class="abc-ul">
              <li class="abc-li"
                  v-for="(item,index) in item.lists"
                  :key="index"
                  @click="changeLocalCity(item)">
                {{item}}
              </li>
              <li class="abc-empty"></li>
              <li class="abc-empty"></li>
              <li class="abc-empty"></li>
              <li class="abc-empty"></li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations } from "vuex"
import Bscroll from 'better-scroll'
export default {
  props: ["hotCityList", "cityList"],
  data () {
    return {
      scroll: "",
    }
  },
  mounted () {

    let wrapper = this.$refs["container"];
    this.scroll = new Bscroll(wrapper, { observeDOM: true });
  },
  methods: {
    ...mapMutations(['changeMyCity']),
    changeLetter (choosedLetter) {
      this.scroll.scrollToElement(this.$refs.cityList[choosedLetter - 1], 600);
    },
    changeLocalCity (localCity) {
      // console.log(localCity);
      this.changeMyCity(localCity);
      this.$router.push("/");
    }

  },
}
</script>
<style  scoped>
.wrapper {
  position: absolute;
  overflow: hidden;
  bottom: 0;
  right: 0;
  top: 1.5rem;
  left: 0;
  background: rgb(244, 244, 244);
}
.hot-title {
  height: 0.8rem;
  line-height: 0.8rem;
  padding-left: 0.2rem;
  font-size: 0.32rem;
}
.hot-ul {
  display: flex;
  width: 100%;
  height: 4rem;
  flex-wrap: wrap;
  justify-content: space-between;
  align-content: space-between;
}
.hot-li {
  display: block;
  box-sizing: border-box;
  width: 33.1%;
  height: 0.98rem;
  line-height: 0.98rem;
  font-size: 0.32rem;
  background: #fff;
  flex-shrink: 0;
  text-align: center;
}
/* letter-css */
.letter-title {
  height: 0.8rem;
  line-height: 0.8rem;
  padding-left: 0.2rem;
  font-size: 0.32rem;
}
.letter-ul {
  display: flex;
  width: 100%;
  height: 4.5rem;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  background: #fff;
}
.letter-li,
.letter-empty {
  display: block;
  box-sizing: border-box;
  width: 16%;
  line-height: 0.97rem;
  font-size: 0.32rem;
  font-weight: bold;
  background: #fff;
  flex-shrink: 0;
  text-align: center;
}

/* abc-css */
.abc-title {
  height: 0.8rem;
  line-height: 0.8rem;
  padding-left: 0.2rem;
  font-size: 0.32rem;
  font-weight: bold;
}
.abc-ul {
  display: flex;
  width: 100%;
  flex-wrap: wrap;
  justify-content: space-between;
}
.abc-li,
.abc-empty {
  display: block;
  box-sizing: border-box;
  width: 24.7%;
  line-height: 0.97rem;
  font-size: 0.28rem;
  background: #fff;
  flex-shrink: 0;
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  border: 1px solid rgb(244, 244, 244);
  border-left: none;
  border-right: none;
  margin-top: -1px;
  padding-left: 0.2rem;
  padding-right: 0.2rem;
}
.letter-empty,
.abc-empty {
  height: 0;
  border: none;
  margin-top: 0;
  margin-bottom: 0;
  visibility: hidden;
  border: 0px;
}
</style>>
